package main

import (
	"net/http"
	"fmt"
	"log"
	"bytes"
)

func main() {
	http.HandleFunc("/", sayHello)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
	//err2 := http.ListenAndServe(":7788", nil)
	//if err2 != nil {
	//	log.Fatal("ListenAndServe: ", err2)
	//}
}
func sayHello(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	fmt.Println(r.Form)
	fmt.Println(r.URL.Host)
	fmt.Println(r.URL.Scheme)
	fmt.Println(r.URL.Path)
	fmt.Println(r.Form["name"])
	var nameVal string
	for k, v := range r.Form {
		fmt.Println("key:", k)
		if k == "name" {
			nameVal = v[0]
		}
		fmt.Println("value:", v)
	}
	s := AppendStr("Hello", " ", nameVal)
	fmt.Println(w, s)
	w.Write([]byte(s))
}

func AppendStr(s ... string) string {
	var bf bytes.Buffer
	for i := 0; i < len(s); i++ {
		bf.WriteString(s[i])
	}
	fmt.Println(bf.String())
	return bf.String()
}
